'use strict';

/**
 * @description 收藏表模型
 * */
module.exports = app => {
  const { INTEGER } = app.Sequelize;

  const Collection = app.model.define('collection', {
    houseId: {
      type: INTEGER,
      allowNull: true,
      comment: '房屋id',
    },
    cid: {
      type: INTEGER,
      allowNull: true,
      comment: '论坛id',
    },
    uid: {
      type: INTEGER,
      allowNull: false,
      comment: '用户id',
    },
  });

  Collection.associate = () => {
    app.model.Collection.belongsTo(app.model.House, {
      foreignKey: 'houseId',
    });
    app.model.Collection.belongsTo(app.model.Comment, {
      foreignKey: 'cid',
    });
    app.model.Collection.belongsTo(app.model.User, {
      foreignKey: 'uid',
    });
  };

  return Collection;
};
